﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarketMS;
using Model;
using System.Data.SqlClient;

namespace DAL
{
    public class GoodsDbhelper
    {
        public List<GoodsInfo> SelectGoods(string shuju)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=WIN-01701092026;Initial Catalog=master;Integrated Security=True");
            string sql = string.Format(" select * from GoodsInfo where GoodsCode like '%"+ shuju+"%'");
            SqlCommand cmd = new SqlCommand(sql,conn);
            conn.Open();
            SqlDataReader dr=cmd.ExecuteReader();
            GoodsInfo ad=null;
            List<GoodsInfo> listgoods = new List<GoodsInfo>();
            while (dr.Read())
            {
                ad = new GoodsInfo();
                ad.GoodsCode = dr["GoodsCode"].ToString();
                ad.GoodsName = dr["GoodsName"].ToString();
                ad.OriginPrice = Convert.ToDouble(dr["OriginPrice"]);
                ad.SalePrice=Convert .ToDouble (dr["SalePrice"]);
                ad.Stock = Convert.ToInt32(dr["Stock"]);
                ad.Supplier=Convert.ToInt32(dr["Supplier"]);
                ad.Unit=dr["Unit"].ToString();
                ad.Company=Convert.ToInt32(dr["Company"]);
                listgoods.Add(ad);

            }
            dr.Close();
            conn.Close();
            return listgoods;
            
            
        }

    }
}
